package demo03;

import java.util.Random;
import java.util.Scanner;

public class Test02Random {
    public static void main(String[] args) {
        Random r = new Random();
        int number = r.nextInt(100) + 1;
        while (true){
            int guessNumber = guessNumber();
            if(isSame(guessNumber,number)){
                break;
            }
        }

    }

    public static int guessNumber() {
        System.out.println("请输入您猜测的数字");
        return new Scanner(System.in).nextInt();
    }
    public static boolean isSame(int guessNumber,int number){
        if (guessNumber > number) {
            System.out.println("猜测的数字太大了,请重新猜测");
            return false;

        } else if (guessNumber < number) {
            System.out.println("猜测的数字太小了,请重新猜测");
            return false;

        } else {
            System.out.println("恭喜你猜对了");
            return true;
        }
    }
}

